package com.shanzmoo.admin.web.store;

import com.shanzmoo.admin.domain.dto.StorePurchasingAgentSaveDTO;
import com.shanzmoo.admin.domain.dto.StorePurchasingAgentUpdateDTO;
import com.shanzmoo.admin.manager.store.StorePurchasingAgentManager;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.db.store.entity.query.StorePurchasingAgentQuery;
import com.shanzmoo.db.store.entity.vo.StorePurchasingAgentVO;
import com.shanzmoo.db.store.service.IStorePurchasingAgentService;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;

/**
 * 仓库采购员 控制层
 *
 * @author Gzhao 2021-03-18
 */
@Api(tags = "仓库采购员")
@RestController
@RequestMapping("/store/purchasing-agent")
public class StorePurchasingAgentController {

    @Autowired
    private IStorePurchasingAgentService storePurchasingAgentService;
    @Autowired
    private StorePurchasingAgentManager storePurchasingAgentManager;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<StorePurchasingAgentVO>> pageList(@Valid @RequestBody StorePurchasingAgentQuery query) {
        PageRespBase<StorePurchasingAgentVO> pageList = storePurchasingAgentManager.queryPage(query);
        return SHttpResponse.ok(pageList);
    }

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody StorePurchasingAgentSaveDTO saveDto) {
        storePurchasingAgentManager.add(saveDto, CurrentUserCache.getUserId());

        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "启用/禁用")
    @GetMapping("/updateStatus")
    public SHttpResponse<Boolean> updateStatus(@RequestParam(value = "id") Integer id) {
        storePurchasingAgentManager.updateStatus(id);

        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody StorePurchasingAgentUpdateDTO updateDto) {
        storePurchasingAgentService.updateById(updateDto.convertEntity());
        return SHttpResponse.ok(Boolean.TRUE);
    }
 }
